package com.fun.demo.fun.kayang;

import java.io.File;
import java.net.URI;
import java.awt.Desktop;

public class DesktopExample {
    public static void main(String[] args) {
        // 检查 Desktop 是否可用
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();

            try {
                // 尝试打开网页
                if (desktop.isSupported(Desktop.Action.BROWSE)) {
                    URI url = new URI("http://www.example.com");
                    desktop.browse(url);
                }

                // 尝试打开文件
                File file = new File("/path/to/file.txt");
                if (file.exists() && desktop.isSupported(Desktop.Action.OPEN)) {
                    desktop.open(file);
                }
            } catch (Exception e) {
                System.err.println("Error: " + e.getMessage());
            }
        } else {
            System.out.println("Desktop is not supported on this platform.");
        }
    }
}
